Ext.define('component.business.window',{
	extend : 'Ext.window.Window',

	config : {
		roomId : '',
		businessStatus:''
	},
	initComponent : function() {
		var me = this;
		var roomId = this.roomId;
		var businessStatus = this.businessStatus;
		var menu = this.menu;
		var projectId = this.projectId;
		var gridStore = Ext.create('Ext.data.Store', {
		    fields: ["businessId","customerName","sex","idCardId","mobile","status","","businessStatus","btnBusiness"],
		    //是否在服务端排序 （true的话，在客户端就不能排序）
		    remoteSort: false,
		    proxy: {
		        type: 'ajax',
		        url: jypath+'/marketing/room/findBusCustomerInfo',
		        reader: {  
		            type: 'json', 
		            root: 'obj'
		        },
		        actionMethods: {read: 'POST'},
	            extraParams:{
	            	roomId:roomId,
	            	businessCode:businessStatus
	            }
		    },
		    autoLoad:true
		});
		
		
		var columns = [{
			text : "ID",
			dataIndex : 'businessId',
			hidden : true
		},{
			text:'客户姓名',
			dataIndex:'customerName',
			width:'15%'
		},{
			text : "性别",
			dataIndex : 'sex',
			width:'20%'
			
		}, {
			text : "证件号码",
			dataIndex : 'idCardId',
			width:'20%'
		},{
			text : "手机号码",
			dataIndex : 'mobile',
			width:'20%'
		
		},{
			text : "状态",
			dataIndex : 'status',
			width:'20%'
		}];
		
		
		
		var gridPanel=Ext.create('Ext.grid.Panel', {
			region : 'center',
			columnLines: true,
	        viewConfig: {
	            stripeRows: true
	        },
			store : gridStore,
			columns : columns,
			tbar:[{
				text:'确认',
				icon:jypath+'/resources/ExtJSicons/arrow/add.png',
				handler:function(){
			     	var record = gridPanel.getSelectionModel().getLastSelected();
			     	if(record!=null){
			     		if(record.data.btnBusiness=="1"){ //认购
                			location.href=jypath+"/customer/subscribe/toAdd?payDepositId="+record.data.businessId+"&returnUrl=,marketing,pin,index";
                		}else if(record.data.btnBusiness=="2"){ //签约
                			if(record.data.businessStatus=="0"){ //认筹转签约
                				location.href=jypath+"/customer/signed/toAdd?payDepositId="+record.data.businessId+"&returnUrl=,marketing,pin,index";
                			}else if(record.data.businessStatus=="1"){ //认购转签约
                				location.href=jypath+"/customer/signed/toAdd?subscribeId="+record.data.businessId+"&returnUrl=,marketing,pin,index";
                			}
                		}
                	}else{
                		 Ext.Msg.alert("提示", "请选择客户!");
                	}
                		
                		
				}
			},{
				text:'取消',
				icon:jypath+'/resources/ExtJSicons/arrow/arrow_turn_left.png',
				handler:function(){
					me.close();
				}
			}
			],	
			selModel:Ext.create('Ext.selection.CheckboxModel', {
				checkOnly:true,
				mode:'single',
				allowDeselect:true
			})
		});
		function locationHref(businessStatus){
			if(businessStatus=="1"){
   			 location.href=jypath + "/customer/subscribe/toAdd?roomId="+roomId+"&menu="+menu+"&returnUrl=,marketing,room,index(menu)"+menu+"&projectId="+projectId;
	   		}else if(businessStatus=="2"){
	   			 location.href=jypath+ "/customer/signed/toAdd?roomId="+roomId+"&menu="+menu+"&returnUrl=,marketing,room,index(menu)"+menu+"&projectId="+projectId;
	   		}
		}
/*		var obc = Ext.create('Ext.panel.Panel', {
			region: 'north',   
			width: 700,
			height:50,
			layout: 'border',
			defaults: {
			   split: false,                 //是否有分割线
			   collapsible: false,           //是否可以折叠
			   bodyStyle: 'padding:15px'
			},
			items:[{
				   region: 'north',            //子元素的方位：north、west、east、center、south
			        xtype: "panel",
			        html: "<span style='color:red'>注意*:当没有可选择的客户,点击确认,直接进行此业务</span>",
			}]
		});*/
		var defaultConfig = {
				frame:true,
				title : '选择客户',
				width: 700,
			    height: 500,
		        modal: true,
				layout : 'border',
				items:[gridPanel]
			};
			Ext.apply(this,defaultConfig);
			this.callParent();
		
		
	}
});